#include <stdio.h>

#define LEN 8

int find(int *num, int len, int v)
{
	int i = 0, j = len - 1, m;
	
	while (i <= j) {
		m = i + (j - i) / 2;
		if (num[m] == v)
			return m;
		if (num[i] < num[m]) { 
			if (v < num[m] && v >= num[i])
				j = m - 1;
			else 
				i = m + 1;
		} else {
			if (v > num[m] && v <= num[j])
				i = m + 1;
			else 
				j = m - 1;
		}
	}
	return -1;
}

int main() 
{
	int num[] = {1, 2, 3, 4, 5, -3, -2, -1};
	int pos, v;

	v = -3;
	pos = find(num, LEN, v);
	printf("v:%d:pos:%d\n", v, pos);

	v = 5;
	pos = find(num, LEN, v);
	printf("v:%d:pos:%d\n", v, pos);

	return 0;
}
